package com.content.view.Frame.MainPanel.MPMyShelf
{
	import com.content.model.Const.TransitionType;
	import com.content.model.GlobalVarProxy;
	import com.content.model.LoadedAssets.ConfigProxy;
	import com.content.model.LoadedAssets.SkinProxy;
	import com.content.model.OnlineRes.OnlineResType;
	import com.content.view.Frame.Content.Content;
	import com.content.view.Frame.MainPanel.MPBase;
	import com.content.view.Frame.MainPanel.MPBaseMediator;
	import com.content.view.Share.Player.AudioPlayer_Mediator;
	import com.content.view.Share.Player.BookPlayer_Mediator;
	import com.content.view.Share.Player.VideoPlayer_Mediator;
	import com.library.core.IDisposable;
	
	import flash.display.Sprite;
	import flash.events.DataEvent;
	
	import org.puremvc.as3.interfaces.IMediator;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.mediator.Mediator;

	public final class MPMyShelf_Mediator extends MPBaseMediator
	{
		public static const NAME:String							= 'MPMyShelf';
		
		public function MPMyShelf_Mediator(viewComponent:Object=null)
		{
			super(this, NAME, viewComponent );
		}
		
		override public function onRegister():void
		{
			//var bgSkin:Sprite = new SkinProxy.IMG_BG_MainPanel() as Sprite;				
			_view = new MPMyShelf(	pConfig.UI_MainPanel_MarginTop,
				pConfig.UI_MainPanel_MarginBottom,
				pConfig.UI_MainPanel_MarginLeft,
				pConfig.UI_MainPanel_MarginRight,
				pConfig.UI_CBarL1_Width + pConfig.UI_CBarL1_MarginLeft,
				M_Audio, M_Video, M_Book, null);			
			ParentView.addChild( _view );
			
			_view.addEventListener(MPBase.ON_SHOWN, OnShown);
			_view.addEventListener(MPMyShelf.CHOOSE_RESOURCE, OnChooseResType);
		}
		
		/* Event Handler
		* ----------------------------------------------------------- */
		private function OnShown(evt:DataEvent):void{
			pWebAPI.GetPurchasedItemsByRes( MPMyShelf(_view).FeedUpdate );
		}
		
		private function OnChooseResType(evt:DataEvent):void{
			switch (evt.data)
			{
				case "tab1":
					pWebAPI.GetPurchasedItemsByRes(MPMyShelf(_view).FeedUpdate);
					break;
				case "tab2":
					pWebAPI.GetPurchasedItemsByRes(MPMyShelf(_view).FeedUpdate, OnlineResType.BOOK);
					break;		
				case "tab3":
					pWebAPI.GetPurchasedItemsByRes(MPMyShelf(_view).FeedUpdate, OnlineResType.VIDEO);
					break;
				case "tab4":
					pWebAPI.GetPurchasedItemsByRes(MPMyShelf(_view).FeedUpdate, OnlineResType.AUDIO);
					break;
			}
		}
		
		override public function Dispose():void	{
			_view.removeEventListener(MPBase.ON_SHOWN, OnShown);
			_view.removeEventListener(MPMyShelf.CHOOSE_RESOURCE, OnChooseResType);
		}
		
		private function get M_Audio():AudioPlayer_Mediator{return facade.retrieveProxy( AudioPlayer_Mediator.NAME ) as AudioPlayer_Mediator;}	
		private function get M_Video():VideoPlayer_Mediator{return facade.retrieveProxy( VideoPlayer_Mediator.NAME ) as VideoPlayer_Mediator;}	
		private function get M_Book():BookPlayer_Mediator{return facade.retrieveProxy( BookPlayer_Mediator.NAME ) as BookPlayer_Mediator;}	
	}
}